﻿using System;
using System.Reflection;

namespace TypeBuilderFx.Core
{
    /// <summary>Represents a named parameter on a method or constructor.</summary>
    /// <remarks>Value type pattern:  this object is immutable.</remarks>
    public class MethodParameter
    {
        private readonly string _name;
        private readonly Type _type;
        private readonly ParameterAttributes _attributes = ParameterAttributes.None;

        /// <summary>Construct a value type.</summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="attributes"></param>
        public MethodParameter(string name, Type type, ParameterAttributes attributes)
            : this(name, type)
        {
            _attributes = attributes;
        }

        /// <summary>Construct a value type.</summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        public MethodParameter(string name, Type type)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            _name = name;
            _type = type;
        }

        /// <summary>Exposes the name of the parameter.</summary>
        public string Name
        {
            get { return _name; }
        }

        /// <summary>Exposes the type of the parameter.</summary>
        public Type Type
        {
            get { return _type; }
        }

        /// <summary>Exposes the parameter attributes.</summary>
        /// <remarks>Default is <see cref="ParameterAttributes.In"/>.</remarks>
        public ParameterAttributes Attributes
        {
            get { return _attributes; }
        }
    }
}